/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
 */
package td.client.view;

import td.client.presenter.RootPresenter;
import td.client.presenter.handlers.RootUiHandlers;
import td.client.ui.Button;
import td.client.ui.TextBox;

import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.google.inject.Singleton;

/**
 * @author Artem Shamsutdinov
 * 
 */
@Singleton
public class RootView extends AbstractViewWithUiHandlers<RootUiHandlers>
		implements RootUiHandlers.MyView {

	@UiField
	Button loginJoinButton;

	@UiField
	Button logoutButton;
	@UiField
	HTMLPanel leftNavigationPanel;
	@UiField
	HTMLPanel contentPanel;
	@UiField
	HTMLPanel rightNavigationPanel;
	@UiField
	Label greetingLabel;
	@UiField
	TextBox searchText;
	@UiField
	Button searchButton;
	@UiField
	Button surveyButton;

	public interface Binder extends UiBinder<Widget, RootView> {
	}

	@Inject
	public RootView(Binder binder) {
		widget = binder.createAndBindUi(this);
	}

	@Override
	public void setInSlot(Object slot, Widget content) {
		if (slot == RootPresenter.SLOT_leftNavigation) {
			leftNavigationPanel.clear();
			if (content != null) {
				leftNavigationPanel.add(content);
			}
		} else if (slot == RootPresenter.SLOT_content) {
			contentPanel.clear();
			if (content != null) {
				contentPanel.add(content);
			}
		} else if (slot == RootPresenter.SLOT_rightNavigation) {
			rightNavigationPanel.clear();
			if (content != null) {
				rightNavigationPanel.add(content);
			}
		} else {
			super.setInSlot(slot, content);
		}
	}

	// FIXME: once prototype is merged in
	// @UiHandler("loginJoinButton")
	// public void loginJoinButtonClick(ClickEvent event) {
	// getUiHandlers().presentLoginDialog();
	// }
	//
	// @UiHandler("logoutButton")
	// public void logoutButtonClick(ClickEvent event) {
	// getUiHandlers().doLogout();
	// }

	@Override
	public void onLogin(String greeting) {
		// greetingLabel.setText(greeting);
		// loginJoinButton.setVisible(false);
		// logoutButton.setVisible(true);
	}

	@Override
	public void onLogout() {
		// greetingLabel.setText(MAIN.HELLO_READER);
		// loginJoinButton.setVisible(true);
		// logoutButton.setVisible(false);
	}

	public Button getLoginJoinButton() {
		return loginJoinButton;
	}

	public Button getLogoutButton() {
		return logoutButton;
	}

	public Label getGreetingLabel() {
		return greetingLabel;
	}

	public TextBox getSearchText() {
		return searchText;
	}

	public Button getSearchButton() {
		return searchButton;
	}

	public Button getSurveyButton() {
		return surveyButton;
	}

}
